/*
 * @Descripttion: 将收到的消息文本转发给前端
 * @version: 1.0
 * @Author: 自由如风
 * @Date: 2021-05-19 11:47:47
 * @LastEditors: 自由如风
 * @LastEditTime: 2021-05-23 14:17:56
 */
const { Plugin } = require('weixin-nodejs');
const { wss } = require('../index')

/** 将 微信 表情转换成 img 标签 */
const qqWechatEmotionParser = require('qq-wechat-emotion-parser');

class Server extends Plugin {
    test() {
        return this.req.is('text') && this.store.get('barrageRoom');// 判断是否有弹幕间
    }
    process() {
        // 组织数据
        const barrage = {
            avatar: this.store.get('user').headimgurl,
            content: qqWechatEmotionParser(this.req.text.Content),
            openId: this.params.FromUserName
        }

        wss.sendBullet(this.store.get('barrageRoom'), barrage); // 发送
    }
}

module.exports = Server